package com.gsj.maintain.controller;

import com.gsj.common.pojo.R;
import com.gsj.maintain.pojo.entity.TabMtShop;
import com.gsj.maintain.pojo.vo.MtRecordVo;
import com.gsj.maintain.pojo.vo.MtShopVo;
import com.gsj.maintain.service.MtShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: clms-nine
 * @description: 维修厂的控制层
 * @author: 郭书江
 * @create: 2021-07-23 18:54
 **/
@RestController
@RequestMapping("/maintain/shop")
@Api(value = "/maintain/shop")

public class MtShopController {

    @Autowired
    private MtShopService mtShopService;

    //查询维修厂列表
    @ApiOperation(value = "查询维修厂列表",httpMethod = "POST")

    @PostMapping("initMtShopTable/{currentPage}/{pageSize}")
    public R initMtShopTable(@PathVariable("currentPage")Integer currentPage,
                               @PathVariable("pageSize")Integer pageSize,
                               @RequestBody MtShopVo mtShopVo){
        return mtShopService.findMtShopByPage(currentPage, pageSize, mtShopVo);
    }
    //添加维修厂
    @ApiOperation(value = "添加维修厂",httpMethod = "POST")
    @PostMapping("insertMtShop/{username}")
    public R insertMtShop(@ApiParam(value = "TabMtShop实体类") @RequestBody TabMtShop mtShop,
                          @ApiParam(value = "操作人name") @PathVariable("username") String username){
        return mtShopService.insert(mtShop,username);
    }
    //更改状态
    @ApiOperation(value = "更改状态",httpMethod = "PUT")
    @PutMapping("up/{id}/{status}")
    public R upStatus(@ApiParam(value = "类型主键ID") @PathVariable("id") Integer id,
                      @ApiParam(value = "status状态")@PathVariable("status") Integer status){
        return mtShopService.upStatus(id,status);
    }
    //删除
    @ApiOperation(value = "删除",httpMethod = "DELETE")
    @DeleteMapping("del/{id}")
    public R del(@ApiParam(value = "类型主键ID") @PathVariable("id") Integer id){
        return mtShopService.del(id);
    }
    //根据id修改维修厂信息
    @ApiOperation(value = "根据id修改维修厂信息",httpMethod = "PUT")
    @PutMapping("updateMtShopById")
    public R update(@ApiParam(value = "TabMtShop实体类") @RequestBody TabMtShop mtShop){
        return mtShopService.up(mtShop);
    }
    //点修改时根据id回显数据
    @ApiOperation(value = "点修改时根据id回显数据",httpMethod = "GET")
    @GetMapping("selById/{id}")
    public R selById(@ApiParam(value = "类型主键ID") @PathVariable("id") Integer id){
        return mtShopService.selById(id);
    }

    //名称校验
    @ApiOperation(value = "名称校验",httpMethod = "POST")
    @PostMapping("selMtShopName")
    public R selUserName(@ApiParam(value = "TabMtShop实体类")
                             @RequestBody TabMtShop mtShop){
        return mtShopService.selMtShopName(mtShop);
    }

    //查询给添加维修记录使用作为下拉框
    @ApiOperation(value = "查询给添加维修记录使用作为下拉框",httpMethod = "GET")
    @GetMapping("selectListAll")
    public R selById(){
        return mtShopService.selectListAll();
    }

}
